import Mock from "mockjs";

import { uuid, orderBy } from "../utils";

const sysProject = localStorage.getItem("sys_project");
const project = sysProject
  ? JSON.parse(sysProject)
  : [
    {
      ow_name: "王小虎",
      village: "宁德小区",
      floor: "12#1201",
      address: "上海市普陀区金沙江路 198 弄",
      phone: "15800000000",
      c_price: "15300",
      status: "待跟进",
      create_time: new Date().getTime(),
      create_user: "王五",
      create_uid: "16548221"
    },
    {
      ow_name: "李大伟",
      village: "翠微小区",
      floor: "2#201",
      address: "上海市普陀区金沙江路 518 弄",
      phone: "15800000000",
      c_price: "15300",
      status: "待跟进",
      create_time: new Date().getTime(),
      create_user: "王五",
      create_uid: "16548221"
    },
    {
      ow_name: "张三",
      village: "阳光小区",
      floor: "2#601",
      address: "上海市普陀区金沙江路 118 弄",
      phone: "15800000000",
      c_price: "15300",
      status: "待跟进",
      create_time: new Date().getTime(),
      create_user: "王五",
      create_uid: "16548221"
    }
  ];

const sysPlan = localStorage.getItem("sys_plan");
const plan = sysPlan
  ? JSON.parse(sysPlan)
  : [
    {
      number: 1,
      planName: "方案一",
      planId: "3FO47FAIRKI5",
      create_time: new Date().getTime(),
      createName: "王五",
    },
    {
      number: 2,
      planName: "方案二",
      planId: "3FO47N8UB3TV",
      create_time: new Date().getTime(),
      createName: "王五",
    },
    {
      number: 3,
      planName: "方案三",
      planId: "3FO47N8UB3TV",
      create_time: new Date().getTime(),
      createName: "王五",
    },
  ];


Mock.mock("project/list", "get", () => ({ result: orderBy(project) }));
Mock.mock("project/list2", "get", () => ({ result: orderBy(plan) }));


// 新增项目接口
Mock.mock("/api3/fslmrp/2", "post", options => {
  const body = JSON.parse(options.body);

  project.push({
    ...body,
    // create_time: new Date().getTime(),
  });

  // 本地保存
  localStorage.setItem("sys_project", JSON.stringify(project));

  return {
    result: {
      err: 0,
      msg: "添加成功！"
    }
  };




});


// 新增方案接口
Mock.mock("project/save2", "post", options => {
  const body = JSON.parse(options.body);

  plan.push({
    ...body,
    // create_time: new Date().getTime(),
  });

  // 本地保存
  localStorage.setItem("sys_plan", JSON.stringify(plan));

  return {
    result: {
      err: 0,
      msg: "添加成功！"
    }
  };

});